import { axios } from '@/utils/request'

/**
 * 查询代码生成配置列表
 * @param query
 * @returns {*}
 */
export function listTable(query) {
  return axios({
    baseURL: process.env.VUE_APP_GENERATOR_API,
    headers: { 'datasource': localStorage.getItem("dataName") },
    url: '/tool/gen/list',
    method: 'get',
    params: query
  })
}

/**
 * 查询代码生成配置详情
 * @param tableId
 * @returns {*}
 */
export function getGenTable(tableId) {
  return axios({
    baseURL: process.env.VUE_APP_GENERATOR_API,
    headers: { 'datasource': localStorage.getItem("dataName") },
    url: '/tool/gen/' + tableId,
    method: 'get'
  })
}

/**
 * 查询数据库表列表
 * @param query
 * @returns {*}
 */
export function listDbTable(query) {
  return axios({
    baseURL: process.env.VUE_APP_GENERATOR_API,
    headers: { 'datasource': localStorage.getItem("dataName") },
    url: '/tool/gen/db/list',
    method: 'get',
    params: query
  })
}

/**
 * 修改代码生成配置
 * @param data
 * @returns {*}
 */
export function updateGenTable(data) {
  return axios({
    baseURL: process.env.VUE_APP_GENERATOR_API,
    headers: { 'datasource': localStorage.getItem("dataName") },
    url: '/tool/gen',
    method: 'put',
    data: data
  })
}

/**
 * 导入表配置
 * @param data
 * @returns {*}
 */
export function importTable(data) {
  return axios({
    baseURL: process.env.VUE_APP_GENERATOR_API,
    headers: { 'datasource': localStorage.getItem("dataName") },
    url: '/tool/gen/importTable',
    method: 'post',
    params: data
  })
}

/**
 * 预览生成代码
 * @param tableId
 * @returns {*}
 */
export function previewTable(tableId) {
  return axios({
    baseURL: process.env.VUE_APP_GENERATOR_API,
    headers: { 'datasource': localStorage.getItem("dataName") },
    url: '/tool/gen/preview/' + tableId,
    method: 'get'
  })
}

/**
 * 删除代码生成配置
 * @param tableId
 * @returns {*}
 */
export function delTable(tableId) {
  return axios({
    baseURL: process.env.VUE_APP_GENERATOR_API,
    headers: { 'datasource': localStorage.getItem("dataName") },
    url: '/tool/gen/' + tableId,
    method: 'delete'
  })
}

/**
 * 生成代码-生成到文件夹
 * @param tableNames
 * @returns {*}
 */
export function downloadPathCode(tableNames) {
  return axios({
    baseURL: process.env.VUE_APP_GENERATOR_API,
    headers: { 'datasource': localStorage.getItem("dataName") },
    url: '/tool/gen/downloadPathCode?tables=' + tableNames,
    method: 'get'
  })
}

/**
 * 同步数据库最新表字段
 * @param tableName
 * @returns {*}
 */
export function syncDb(data) {
  return axios({
    baseURL: process.env.VUE_APP_GENERATOR_API,
    headers: { 'datasource': localStorage.getItem("dataName") },
    url: '/tool/gen/syncDb',
    method: 'post',
    params: data
  })
}
